Hi, |
Re: easiest way to sort? |
Re: easiest way to sort?
Here is an example using skiplist to sort: Skip skpList=createString put(skpList,"d","dog") put(skpList,"c","cat") put(skpList,"b","boy") put(skpList,"a","alligator") string s for s in skpList do print s "\n"
|
Re: easiest way to sort? OurGuest - Thu Jul 14 08:24:26 EDT 2011
Here is an example using skiplist to sort: Skip skpList=createString put(skpList,"d","dog") put(skpList,"c","cat") put(skpList,"b","boy") put(skpList,"a","alligator") string s for s in skpList do print s "\n"
Little more clarification: retrievals are sorted lowest first for KEY string and integer and I suppose real and char; other data types come out non-sensically, what does it mean to sort a 'Link' handle? (OK, they come out in the order in which they are stored in memory).
Skip skpList=createString() // 'createString' ALWAYS when KEY is type 'string'; otherwise 'create'
put(skpList,"d","dog")
put(skpList,"c","cat")
put(skpList,"b","boy")
put(skpList,"b","boyX") // This one ignored since key 'b' already exists
put(skpList,"a","alligator")
string Data, Key
for Data in skpList do // Notice here we have to remember what 'type' is the Data
{ Key = (string key skpList) // Notice here we have to remember what 'type' is the Key
print Key "\t" Data "\n"
}
delete(skpList)
Skip skpLinks = create() // KEY 'int' sequencer, DATA: 'Link'
Link lnk
Object o = current
int Sequencer = 0
for lnk in o ->"*" do
{ put(skpLinks, Sequencer++, lnk)
}
for lnk in skpLinks do
{ Sequencer = (int key skpLinks)
print Sequencer "\t" some info about the link "\n"
}
delete(skpLinks)
|
Re: easiest way to sort? You cannot "sort" a buffer but you can sort the Users before you parse them and put their info into the Buffer.
Change these two lines...
for user in userList do {
bool c = user.disabled // do not display disabled users
...
To these lines...
Skip skpUsers = createString() // KEY 'string' UserName; DATA: 'User' handle
string Name
for user in userList do {
Name = user.name
put(skpUsers, Name, user)
}
for user in skpUsers do {
bool c = user.disabled // do not display disabled users
... and of course add "delete(skpUsers)" after the loop.
|
testing
testing
// Remove newline f
Buffer bTempStrip = create() // create the temp buffer outside of the function for performance
void StripNewLine(Buffer b)
{
setempty bTempStrip ; // empty the temp buffer
int j,l=length(b)
if (l == 0) return // nothing to do
b2 = ""
for(j=0;j<l;j++) { if(b[j] != '\n') bTempStrip += b[j] }
setempty b; combine (b, bTempStrip, 0) // empty the old buffer, and replace its contents
}
Buffer b1 =create
Buffer b1Alias = b1
b1= "First Line\nSecond Line"
StripNewLine(b1)
print (tempStringOf b1) ""
print "Hey our alias still works: " (tempStringOf b1Alias) ""
delete(b1)
|